<?php
/* @var $this OnlinenewsController */
/* @var $model OnlineNews */
$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
$this->breadcrumbs=array(
	'Online News'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'List OnlineNews', 'url'=>array('index')),
	array('label'=>'Create OnlineNews', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#online-news-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<h1>Tin tức crawler</h1>

<?php echo CHtml::beginForm(); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'online-news-grid',
   'summaryText' =>  '<div class="left">Số dòng: '.CHtml::dropDownList('pageSize',
            $pageSize,
            array(10=>10,20=>20,50=>50,100=>100),
            array(
               'onchange'=>"$.fn.yiiGridView.update('online-news-grid',{ data:{pageSize: $(this).val() }})",
               'style' => 'width:80px',
         )).'</div> Displaying'.' {start}-{end} of {count} '.'results',
	'dataProvider'=>$model->search(),
   'rowHtmlOptionsExpression' => 'array("id"=>"row-".$data->id)',
	'filter'=>$model,
	'columns'=>array(
      array(
         'id' => 'selectedIds',
         'class' => 'CCheckBoxColumn',
         'selectableRows' => 2,
      ),
      array(
         'header' => '<a href="javascript:void(0)">Nội dung</a>',
         'value' => array($this,'gridContent'),
         //'htmlOptions' => array('style' => 'width:600px'),
         'type' => 'raw',
         'filter' => CHtml::textField('News[title]',$model->title),
      ),
      array(
         'name' => 'online_news_category_id',
         'value' => array($this,'gridCate'),
         'htmlOptions' => array('style' => 'width:150px'),
         'filter'=> CHtml::dropDownList(
               'OnlineNews[online_news_category_id]',
               $model->online_news_category_id,
               Category::model()->getTree(Category::model()->getAll()),
               array(
                  'empty' => '-- Tất cả --',
                  'style' => 'width:150px'
               )),
      ),
      array(
         'name' => 'datetime',
         'htmlOptions' => array('style' => 'width:120px'),
      ),
		/*
		'online_news_category_id',
		'vendor_link',
		'has_main_image',
		'keywords',
		'sync',
		*/
	),
)); ?>
<div>
<?php echo CHtml::submitButton('Phê duyệt',
array(
   'name' => 'ApproveButton',
   'class' => 'btn btn-success',
   'style' => 'margin-right:10px',
   'confirm' => 'Bạn có chắc chắn muốn duyệt những tin đã chọn',
)); ?>
<?php echo CHtml::submitButton('Xóa', 
array(
   'name' => 'DeleteButton',
   'confirm' => 'Bạn có chắc chắn muốn xóa những tin đã chọn',
   'class' => 'btn btn-danger'
));
?>
</div>
<?php echo CHtml::endForm(); ?>
<script>
   function approve_news(id){
      if(id > 0){
         var url = '<?php echo Yii::app()->request->baseUrl;?>/admin/onlinenews/handle';
         var success_fnc = function(result){
            if(result.error_code == 200){
               $("#row-"+id).remove();
            }
         }
         handleAjax(url,'POST','json',{'action':'approve','id':id},success_fnc);
      }else{
         alert('id invalid');
      }
   }
   
   function delete_news(id){
      if(id > 0){
         var url = '<?php echo Yii::app()->request->baseUrl;?>/admin/onlinenews/handle';
         var success_fnc = function(result){
            if(result.error_code == 200){
               $("#comment-"+id).remove();
            }
         }
         var conf = confirm("Bạn có chắc chắn muốn xóa tin này ?");
         if(conf)
            handleAjax(url,'POST','json',{'action':'delete','id':id},success_fnc);
      }else{
         alert('id invalid');
      }
   }
   
</script>
